<template>
  <div>
    <el-row>
      <!-- 24份，就会占满整个父容器 -->
      <el-col :span="24">
        <h5>自定义颜色</h5>
        <!-- default-active默认展开的菜单 -->
        <!-- router添加这个属性后，可以根据item的index属性做跳转 -->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-menu-item index="2" @click="home">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <!-- 一级叫目录，有图标 -->
          <el-submenu
            index="1"
            v-for="(item, index) in menuList"
            :key="index+'menu'"
          >
          <!-- template是图表 -->
             <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.title}}</span>
            </template>
            <!-- 二级叫菜单，无图标 -->
            <!-- el-menu-item是二级菜单 -->
            <el-menu-item
              v-for="(submenu, index) in item.children"
              :key="index+'submenu'"
              :index="'/index'+submenu.url"
            >
              {{submenu.title}}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      menuList: [
        {
          title: '系统设置',
          children: [
            {title: '菜单管理', url: '/menu'},
            {title: '角色管理', url: '/role'},
            {title: '管理员管理', url: '/admin'},
          ]
        },
        {
          title: '商城管理',
          children: [
            {title: '商品分类', url: '/category'},
            {title: '角色管理2', url: '/menu'},
            {title: '管理员管理3', url: '/menu'},
          ]
        }
      ]
    }
  },
  methods: {
    home() {
      // 回到首页
      this.$router.push('/index')
    }
  }
};
</script>
<style lang="">
</style>